import {Component, OnInit} from '@angular/core';
import {Nav} from '../../models/nav';
import {NavService} from '../../services/nav/nav.service';
import {animate, state, style, transition, trigger} from '@angular/animations';
import {Router} from '@angular/router';

@Component({
  selector: 'app-container',
  templateUrl: './container.component.html',
  styleUrls: ['./container.component.less']
})
export class ContainerComponent implements OnInit {
  today: Date = new Date();
  user: {
    username?: string;
  } = {};

  navs: Array<Nav> = [];
  openNavs: Array<Nav>;
  isShowMenu: boolean;

  constructor(private navSvr: NavService, private router: Router) {

  }

  ngOnInit() {
    // todo: 获取人物信息
    this.user = {
      username: sessionStorage.getItem('username')
    };

    // todo: 获取人物导航栏
  }

  changeTab(nav: Nav): void {
    for (const item of this.openNavs) {
      /*isActive 用去显示页面框*/
      item.isActive = false;
    }
    /*用于选择的页被选择*/
    nav.isActive = true;
    this.isShowMenu = false;
    this.router.navigateByUrl(nav.link);
  }

  logout(): void {
    // todo: 退出登录
    sessionStorage.removeItem('username');
    this.router.navigateByUrl('/login');
  }

  toSearch(search: string): void {
    /*   console.log(search)*/
    console.log('我是一个未完成的功能');
  }

}
